﻿using System;
using System.Collections.Generic;
using System.Text;

namespace HiLand.Utility.Data
{
    public static class Converter
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static int ToInt32(bool value)
        {
            int result = 0;
            if (value == true)
            {
                result = 1;
            }
            else
            {
                result = 0;
            }

            return result;
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static bool ToBoolean(int value)
        {
            bool result = false;
            if (value <= 0)
            {
                result = false;
            }
            else
            {
                result = true;
            }

            return result;
        }

        public static string ToChineseString(bool value)
        {
            return ToChineseString(value, string.Empty);
        }

        public static string ToChineseString(bool value, string displaySerialName)
        {
            string result = string.Empty;
            if (displaySerialName == null)
            {
                displaySerialName = string.Empty;
            }
            displaySerialName = displaySerialName.ToLower();

            switch (displaySerialName)
            {
                case "effect":
                    if (value == true)
                    {
                        result = "有效";
                    }
                    else
                    {
                        result = "无效";
                    }
                    break;
                default:
                    if (value == true)
                    {
                        result = "是";
                    }
                    else
                    {
                        result = "否";
                    }
                    break;
            }

            return result;
        }

        /// <summary>
        /// 将某个枚举项的字符串值转化成其对应的枚举类型
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="enumItemValue"></param>
        /// <returns></returns>
        public static T ToEnum<T>(string enumItemValue)
        {
            return (T)Enum.Parse(typeof(T), enumItemValue);
        }

        /// <summary>
        /// 获取某个字符串表示的枚举项的数值
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="enumItemValue"></param>
        /// <returns></returns>
        public static int GetEnumValue<T>(string enumItemValue)
        {
            return Convert.ToInt32(ToEnum<T>(enumItemValue));
        }
    }
}
